package com.hqyj.controller;

import com.hqyj.pojo.Employee;
import com.hqyj.service.EmployeeService;
import com.hqyj.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

@Controller
@RequestMapping("/employee")
public class EmployeeController1 {
    @Autowired
    EmployeeService employeeService;
    @Autowired
    JobService jobService;

    //跳转到员工列表
    @RequestMapping("/turnEmployeePage")
    public String employeeListPage() {
        return "employeeList";
    }

    //查询列表
    @RequestMapping(value = "/employeeList",
            method = RequestMethod.POST)
    @ResponseBody
    public HashMap<String, Object> employeeList(Employee employee) {

        HashMap<String, Object> map = employeeService.selectByENumber(employee);
        System.err.println("========" + employee.toString());
        return map;
    }

    //添加员工信息界面
    @RequestMapping("/addEmployeePage")
    public String addEmployeePage() {

        return "employeeAdd";
    }

    //跳转到修改信息页面
    @RequestMapping("/editPage")
    public String editPage() {
        return "employeeEdit";
    }

    //添加员工信息
    @RequestMapping("/addEmployee")
    @ResponseBody
    public HashMap<String, Object> addEmployee(Employee employee) {
        HashMap<String, Object> map = employeeService.addEmployee(employee);

        return map;
    }

    //修改员工信息ui
    @RequestMapping("/employeeEditPage")
    public String employeeEditPage() {
        return "employeeEdit";
    }


    //删除
    @RequestMapping("/deleteBysId")
    @ResponseBody
    public HashMap deleteById(Employee employee) {


        HashMap<String, Object> map = employeeService.deleteByID(employee.getId());

        return map;
    }

    @RequestMapping("/exit")
    public String exit(HttpServletRequest request) {

        request.getSession().invalidate();

        return "login";
    }

    //跳转到更改密码页面
    @RequestMapping("/updatePwd")
    public String updatePasswordPage() {
        return "updatePwd";
    }

    //更改密码
    @RequestMapping("/changPassword")
    @ResponseBody
    public HashMap<String, Object> changePassword(Employee employee) {
        return employeeService.updatePwd(employee);
    }
}